﻿package  {
	import flash.display.MovieClip;
		import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.events.Event;

	public class fpser  extends MovieClip {
		private var lasttime:Number;
		public var fps:Number;
		private var fpscc:Number;
		public var sssa:Timer;
		public var texx:TextField;
		public function fpser() {
			var mlk:Date = new Date();
			lasttime=mlk.getTime(); // -1292601600000
			fps=0;
			fpscc=0;
			sssa=new Timer(1000);
			sssa.addEventListener(TimerEvent.TIMER,fpsupdate);
			this.addEventListener(Event.ENTER_FRAME,efffps);
			sssa.start();
			texx=new TextField();
			var temm:TextFormat=new TextFormat();
			texx.x=0;texx.y=0;
			temm.size = 9;
			temm.color=0xFF0000;
			texx.text="fps:";
			texx.border = true;
			texx.background = false;
			texx.multiline = false;
			texx.wordWrap = true;
			texx.selectable = false;
			texx.width = 60;
			texx.height = 24;
			texx.setTextFormat(temm);	
			this.addChild(texx);
		}
		public function efffps(e:Event)
		{
			fpscc++;
		}
		public function fpsupdate(e:TimerEvent)
		{
			var nt:int;
			var mlk:Date = new Date();
			nt=mlk.getTime(); // -1292601600000
			
			if(Math.abs(nt-lasttime)>=1000)
			{
				//trace(fpscc);
				fps=fpscc/((nt-lasttime)/1000);
				lasttime=nt;
				fpscc=0;
				
				texx.text="fps:"+(fps.toString());
			}
			//nt-=lasttime;
			//fps=(1/nt)*1000;
			//fps=nt;
			
		}
		public function getnowtime():Number
		{
			var mlk:Date = new Date();
			return mlk.getTime(); // -1292601600000
		}

	}
	
}
